<?php
/**
* @package BSI
* @author BestSoft Inc see README.php
* @copyright BestSoft Inc.
* See COPYRIGHT.php for copyright notices and details.
*/
$bsiCore = new bsiHotelCore;
class bsiHotelCore{
	public $config = array();
	public $userDateFormat = "";		
	
	function bsiHotelCore(){		
		$this->getBSIConfig();
		$this->getUserDateFormat();		
	}	
	
	public function get_currency($from_Currency, $to_Currency, $amount) {
				$amount = urlencode($amount);
				$from_Currency = urlencode($from_Currency);
				$to_Currency = urlencode($to_Currency);
				$url = "http://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency";
				$ch = curl_init();
				$timeout = 0;
				curl_setopt ($ch, CURLOPT_URL, $url);
				curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
				curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
				$rawdata = curl_exec($ch);
				curl_close($ch);
				$data = explode('bld>', $rawdata);
				$data = explode($to_Currency, $data[1]);
				return round($data[0], 2);
				}
				
	private function getBSIConfig(){
		$sql = mysql_query("SELECT conf_id, IFNULL(conf_key, false) AS conf_key, IFNULL(conf_value,false) AS conf_value from netbiz_configure");
		while($currentRow = mysql_fetch_assoc($sql)){
			if($currentRow["conf_key"]){
				if($currentRow["conf_value"]){
				$this->config[trim($currentRow["conf_key"])] = trim($currentRow["conf_value"]);
				}else{
					$this->config[trim($currentRow["conf_key"])] = false;
				}
			}
		}
		mysql_free_result($sql);	
	}
	
	private function getUserDateFormat(){		
		$dtformatter = array('dd'=>'%d', 'mm'=>'%m', 'yyyy'=>'%Y', 'yy'=>'%Y');		
		$dtformat = preg_split("@[/.-]@", $this->config['conf_dateformat']);
		$dtseparator = ($dtformat[0] === 'yyyy')? substr($this->config['conf_dateformat'], 4, 1) : substr($this->config['conf_dateformat'], 2, 1);
		$this->userDateFormat = $dtformatter[$dtformat[0]].$dtseparator.$dtformatter[$dtformat[1]].$dtseparator.$dtformatter[$dtformat[2]];	
	}	
	
	public function getMySqlDate($date){
		if($date == "") return "";
		$dateformatter = preg_split("@[/.-]@", $this->config['conf_dateformat']);
		$date_part = preg_split("@[/.-]@", $date);		
		$date_array = array();		
		for($i=0; $i<3; $i++) {
			$date_array[$dateformatter[$i]] = $date_part[$i];
		}
		return $date_array['yy']."-".$date_array['mm']."-".$date_array['dd'];
	}	
	
	public function ClearInput($dirty){
		$dirty = mysql_real_escape_string($dirty);
		return $dirty;
	}	
	
	public function capacitycombo(){
		$chtml = '<select id="capacity" name="capacity" class="input-medium">';
		
		$capacityrow = mysql_fetch_assoc(mysql_query("SELECT Max(capacity) as capa from netbiz_capacity WHERE `id` IN (SELECT DISTINCT (capacity_id) from netbiz_room) ORDER BY capacity"));
				for($i=1; $i<=$capacityrow["capa"]; $i++){ 
					$chtml .=  '<option value="'.$i.'">'.$i.'</option>';
				}
		$chtml .= '</select>';	
		return $chtml;
	}
	
	public function clearExpiredBookings(){		
		$sql = mysql_query("SELECT booking_id from netbiz_bookings WHERE payment_success = false AND ((NOW() - booking_time) > ".intval($this->config['conf_booking_exptime'])." )");
		while($currentRow = mysql_fetch_assoc($sql)){			
			mysql_query("delete from netbiz_invoice WHERE booking_id = '".$currentRow["booking_id"]."'");
			mysql_query("delete from netbiz_reservation WHERE bookings_id = '".$currentRow["booking_id"]."'");	
			mysql_query("delete from netbiz_bookings WHERE booking_id = '".$currentRow["booking_id"]."'");			
		}
		mysql_free_result($sql);
	}
	
	public function loadPaymentGateways() {			
		$paymentGateways = array();
		$sql = mysql_query("SELECT * FROM netbiz_payment_gateway where enabled=true");
		while($currentRow = mysql_fetch_assoc($sql)){	
			$paymentGateways[$currentRow["gateway_code"]] = array('name'=>$currentRow["gateway_name"], 'account'=>$currentRow["account"]);	 
		}
		mysql_free_result($sql);
		return $paymentGateways;
	}
	
	public function encryptCard($creditno){
		$key = 'sdj*sadt63423h&%$@c34234c346v4c43czxcx'; //Change the key here
		$td = mcrypt_module_open('tripledes', '', 'cfb', '');
		srand((double) microtime() * 1000000);
		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
		$okey = substr(md5($key.rand(0, 9)), 0, mcrypt_enc_get_key_size($td));
		mcrypt_generic_init($td, $okey, $iv);
		$encrypted = mcrypt_generic($td, $creditno.chr(194));
		$code = $encrypted.$iv;
		$code = eregi_replace("'", "\'", $code);
		return $code;
	}
	
	public function decryptCard($code){
		$key = 'sdj*sadt63423h&%$@c34234c346v4c43czxcx'; // use the same key used for encrypting the data
		$td = mcrypt_module_open('tripledes', '', 'cfb', '');
		$iv = substr($code, -8);
		$encrypted = substr($code, 0, -8);
		for ($i = 0; $i < 10; $i++) {
			$okey = substr(md5($key.$i), 0, mcrypt_enc_get_key_size($td));
			mcrypt_generic_init($td, $okey, $iv);
			$decrypted = trim(mdecrypt_generic($td, $encrypted));
			mcrypt_generic_deinit($td);
			$txt = substr($decrypted, 0, -1);
			if (ord(substr($decrypted, -1)) == 194 && is_numeric($txt)) break;
		}
		mcrypt_module_close($td);
		return $txt;
	}
	
	public function paymentGateway($code){
		$row = mysql_fetch_assoc(mysql_query("SELECT gateway_name from netbiz_payment_gateway where gateway_code='".$code."'"));
		return  $row['gateway_name'];
	}
	
	public function getInvoiceinfo($bid){
		$invoiceres=mysql_fetch_assoc(mysql_query("SELECT * FROM netbiz_invoice where booking_id='".$bid."'"));			
		return $invoiceres['invoice'];
	}
	public function paymentGatewayName($gcode){
		$row=mysql_fetch_row(mysql_query("select gateway_name from netbiz_payment_gateway where gateway_code='".$gcode."'"));
		return $row[0];
	}
	
	public function getChildcombo(){
		$child_res=mysql_query("SELECT max(`no_of_child`) as mchild FROM `netbiz_room`");
		$rowchild=mysql_fetch_assoc($child_res);
		$childhtml="";
		if($rowchild['mchild']){
			$childhtml.= '<div class="control-group">
                            <label class="control-label" for="checkInDate">'.CHILD_PER_ROOM_TEXT.':</label>
                            <div class="controls">
                            	<select class="input-medium" id="child_per_room" name="child_per_room"><option value="0" selected>'.NONE_TEXT.'</option>' ;
		
			for($k=1;$k<=$rowchild['mchild'];$k++){
				  $childhtml.='<option value="'.$k.'">'.$k.'</option>';
			}
			$childhtml.=' </select></div></div>';
		}
		
		return $childhtml;
	}
	
	
	 
	 public function getExchangemoney_update() {
		$sql=mysql_query("SELECT * FROM netbiz_currency where default_c = 0");
		$default2=mysql_fetch_assoc(mysql_query("SELECT * FROM netbiz_currency where default_c = 1"));
		while($row=mysql_fetch_assoc($sql)){
			$amount=1;
			$amount = urlencode($amount);
			$from_Currency = urlencode($default2['currency_code']);
			$to_Currency = urlencode($row['currency_code']);
			$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
			$ch = curl_init();
			$timeout = 0;
			curl_setopt ($ch, CURLOPT_URL, $url);
			curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
			curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
			$rawdata = curl_exec($ch);
			curl_close($ch);
			$data = explode('"', $rawdata);
			$data = str_replace("\xC2\xA0", "", $data['3']);
			$data = explode(' ',$data);		
			$var = $data['0'];
		//return round($var,3);
			mysql_query("update netbiz_currency set  exchange_rate ='".$var."' where currency_code='".$row['currency_code']."'");
		}
	}
		 
	 public function getExchangemoney($amount1,$to_Currency1){
	      $row=mysql_fetch_assoc(mysql_query("SELECT * FROM netbiz_currency where currency_code = '".$to_Currency1."'"));
		  $exchange_rate=$row['exchange_rate'];
		  $amount        = $amount1*$exchange_rate;
		  return number_format($amount,2);
	 }
	 
	 public function currency_symbol(){
		 $default2=mysql_fetch_assoc(mysql_query("SELECT * FROM netbiz_currency where default_c = 1"));
		 return $default2['currency_symbl'];
		 
	 }
	 public function currency_code(){
		 $default2=mysql_fetch_assoc(mysql_query("SELECT * FROM netbiz_currency where default_c = 1"));
		 return $default2['currency_code'];
	 }
	 
	 public function get_currency_symbol($c_code){
		 $default2=mysql_fetch_assoc(mysql_query("SELECT * FROM netbiz_currency where currency_code = '".$c_code."'"));
		 return $default2['currency_symbl'];
	 }
	 
	  public function get_currency_combo3($c_code){
		  
		  $sql=mysql_query("SELECT * FROM netbiz_currency order by currency_code");
		  $combo='<div class="control-group">
                            <label class="control-label" for="checkInDate">'.CURRENCY_TEXT.':</label>
                            <div class="controls">
                            	<select class="input-medium" name="currency" id="currency">';
		   
		   
		  while($row=mysql_fetch_assoc($sql)){
			  if($row['currency_code'] == $c_code)
			  $combo.='<option value="'.$row["currency_code"].'"  selected="selected">'.$row['currency_code'].'</option>';
			  else
			  $combo.='<option value="'.$row["currency_code"].'">'.$row['currency_code'].'</option>';
		  }
		  $combo.='  </select>
                            </div>
                        </div>';
	      if(mysql_num_rows($sql) == 1){
			
			   $combo='<input type="hidden" name="currency" value="'.$this->currency_code().'" />';
		  }
		  
		  return $combo;
	  }
	  
	   public function get_currency_combo2($c_code){
		  $combo='<select name="currency"  class="input-small" onchange="currency_change(this.value)">';
		   $sql=mysql_query("SELECT * FROM netbiz_currency order by currency_code");
		  while($row=mysql_fetch_assoc($sql)){
			  if($row['currency_code'] == $c_code)
			  $combo.='<option value="'.$row["currency_code"].'"  selected="selected">'.$row['currency_code'].'</option>';
			  else
			  $combo.='<option value="'.$row["currency_code"].'">'.$row['currency_code'].'</option>';
		  }
		   
		  $combo.='</select>';
		  if(mysql_num_rows($sql) == 1){
			  $combo='';
		  }
		  return $combo;
	  }
	  
	  public function exchange_rate_update($type=1){
		  if($type){
			  if($this->config['conf_currency_update_time']!=''){
				  if(time() > ($this->config['conf_currency_update_time'] + 12 * 3600)){
					   $this->getExchangemoney_update();
				 	   mysql_query("update netbiz_configure set conf_value='".time()."' where conf_key='conf_currency_update_time'");
				  }
				
				  
			  }else{
				  $this->getExchangemoney_update();
				  mysql_query("update netbiz_configure set conf_value='".time()."' where conf_key='conf_currency_update_time'");
			  }
		  
	      }else{
			  $this->getExchangemoney_update();
		  }
		  
	  }
	  
	  public function roomtype_photos($selected){
		  global $bsiCore;
		  $rid=$bsiCore->getRoomtypeId($selected);
		  $cid=$bsiCore->getCapacityId($selected);
		  
		  $sql=mysql_query("SELECT * FROM netbiz_gallery where roomtype_id=".$rid." and capacity_id=".$cid);
		  $list_img='';		  
		  if(mysql_num_rows($sql)){
			  while($row=mysql_fetch_assoc($sql)){
			   $list_img.='<img src="gallery/thumb_'.$row['img_path'].'" style="border-style: none" width="425" height="124"/>';			   
			  
			  }
		  }else{
			   $list_img.='<img src="images/no_photo.jpg" />';
		  }
		  //$list_img.='</div>';
		  
		  return $list_img;
	  }
	  
	  public function bt_date_format(){
		  if($this->config['conf_dateformat']=='yy-mm-dd')
		  $df='yy'.$this->config['conf_dateformat'];
		  else
		   $df=$this->config['conf_dateformat'].'yy';
		   
		   return $df;
	  }
	  
	  public function getRoomtypeId($selected){
		  $roomtype_id=explode("_",$selected);
		  
		  return $roomtype_id[0];
	  }
	  public function getCapacityId($selected){
		  $capacity_id=explode("_",$selected);
		  
		  return $capacity_id[1];
	  }
	  
	  public function roomtype($selected){
		  $sql=mysql_query("SELECT * FROM netbiz_roomtype");
		  $data='';		  
		  if(mysql_num_rows($sql)){
			  while($row=mysql_fetch_assoc($sql)){
				  $query=mysql_query("select * from netbiz_capacity");
				  if(mysql_num_rows($query)){
			  		while($res=mysql_fetch_assoc($query)){
						$result=$row['roomtype_ID'].'_'.$res['id'];
						  if($result==$selected)
						  {
							  $data.='<option value="'.$result.'" selected="selected">'.$row['type_name'].' ('.$res['title'].')</option>';
						  }
						  else
						  {
							$data.='<option value="'.$result.'">'.$row['type_name'].' ('.$res['title'].')</option>';		   
						  }
				  
					}
				  }
			  
			  }
		  }
		  
		  return $data;
	  }
	  public function roomtypedesc($roomtype_ID,$count){
		  global $bsiCore;
		  $roomtypeid=$bsiCore->getRoomtypeId($roomtype_ID);
		  $sql=mysql_query("SELECT * FROM netbiz_roomtype where roomtype_ID=".$roomtypeid);
		  if(mysql_num_rows($sql)){
			  $row=mysql_fetch_assoc($sql);
			  	if($count=='part')
				{
				 $data='<p>'.substr($row['description'],0,120).'... <a href="javascript:void(0);" class="roomtype" id="roomtype_descp" alt='.$roomtype_ID.'>Read more</a><span style="color: #cc0e00;">&gt;&gt;</span></p>';			  			  
				}
				else
				{
					$data='<p>'.$row['description'].'</p>';			  			  
				}
		  }
		  
		  return $data;
	  }
	  
	  public function roomFacilities($roomtype_ID){
		  global $bsiCore;
		  $roomtypeid=$bsiCore->getRoomtypeId($roomtype_ID);
		  $sql=mysql_query("select netbiz_facilities.facilities_name from netbiz_room_facilities,netbiz_facilities where netbiz_room_facilities.facilities_id=netbiz_facilities.facilities_id and netbiz_room_facilities.roomtype_ID=".$roomtypeid);
		  if(mysql_num_rows($sql)){
			$data='<ul>';
			while($row=mysql_fetch_assoc($sql)) {
				$data.='<li>'.$row['facilities_name'].'</li>';
			}
			$data.='</ul>';
		  }
		  
		  return $data;
	  }
	  
	  public function roomExtraFeatures($roomtype_ID){
		  global $bsiCore;
		  $roomtypeid=$bsiCore->getRoomtypeId($roomtype_ID);
		  $sql=mysql_query("select netbiz_extra_features.extra_features_id,netbiz_extra_features.extra_features_name,netbiz_extra_features.price from netbiz_room_extra_features,netbiz_extra_features where netbiz_room_extra_features.extra_features_id=netbiz_extra_features.extra_features_id and netbiz_room_extra_features.roomtype_ID=".$roomtypeid);
		  if(mysql_num_rows($sql)){
			//$data='<ul>';
			$data='';
			while($row=mysql_fetch_assoc($sql)) {
				$data.='<li><input name="extra" class="extras" type="checkbox" value="'.$row['extra_features_id'].'" title="'.$row['price'].'" />'.$row['extra_features_name'].'</li>';
			}
			//$data.='</ul>';
		  }
		  
		  return $data;
	  }
	  public function roomOffers($roomtype_ID){
		  global $bsiCore;
		  $roomtypeid=$bsiCore->getRoomtypeId($roomtype_ID);
		  $cid=$bsiCore->getCapacityId($roomtype_ID);
		  $sql=mysql_query("select so.offer_title,so.id from netbiz_room_offers as ro,netbiz_special_offer as so where so.id=ro.offer_id and ro.roomtype_ID=".$roomtypeid." and capacity_id=".$cid." Order by so.id desc");
		  $data='';
		  if(mysql_num_rows($sql)){
			
			while($row=mysql_fetch_assoc($sql)) {
				$data.='<option value="'.$row["id"].'_'.$roomtypeid.'">'.$row["offer_title"].'</option>';
			}			
		  }		  
		  return $data;
	  }
	  
	  public function roomOffersDesc($roomtype_ID,$offer_ID){
		  global $bsiCore;
		  $roomtypeid=$bsiCore->getRoomtypeId($roomtype_ID);
		  $data ='';
		  $sql=mysql_query("select so.description from netbiz_room_offers as ro,netbiz_special_offer as so where so.id=ro.offer_id and ro.roomtype_ID=".$roomtypeid." and ro.offer_id=".$offer_ID);
		  if(mysql_num_rows($sql)){			
			$row=mysql_fetch_assoc($sql); 
				$data=$row['description'];
						
		  }
		  
		  return $data;
	  }
	  
	  public function roomOffersPhotos($offer_id){
		  $sql=mysql_query("SELECT * FROM netbiz_offers_gallery where offer_id=".$offer_id);
		  $list_img='';
		  
		  if(mysql_num_rows($sql)){
			  while($row=mysql_fetch_assoc($sql)){
			   $list_img.='<div class="slide"><img src="gallery/thumb_'.$row['img_path'].'" style="border-style: none" width="262" height="124"/></div>';			   
			  
			  }
		  }else{
			   $list_img.='<div class="slide"><img src="images/no_photo.jpg" /></div>';
		  }
		  
		  return $list_img;
	  }
	  
	  public function getCurrency(){
		  $sql=mysql_query("select * from netbiz_currency order by currency_code");
		  if(mysql_num_rows($sql)){			
			while($row=mysql_fetch_assoc($sql)) {
				$data.='<option value="'.$row["id"].'">'.$row["currency_code"].'</option>';
			}				
						
		  }
		  
		  return $data;
	  }
	  public function getPrice($roomtype_ID,$extra_id){
		  global $bsiCore;
		  $roomtypeid=$bsiCore->getRoomtypeId($roomtype_ID);
		  $data='';
		  $sql=mysql_query("select * from netbiz_currency order by currency_code");
		  if(mysql_num_rows($sql)){			
			while($row=mysql_fetch_assoc($sql)) {
				$data.='<option value="'.$row["id"].'">'.$row["currency_code"].'</option>';
			}				
						
		  }
		  
		  return $data;
	  }
	  
	  public function getCountry(){
		  $data='';
		  $sql=mysql_query("select * from netbiz_country order by country");
		  if(mysql_num_rows($sql)){			
			while($row=mysql_fetch_assoc($sql)) {
				$data.='<option value="'.$row["id"].'">'.$row["country"].'</option>';
			}				
						
		  }
		  
		  return $data;
	  }
	  
	  public function getTotalPrice($selected,$extraPrice,$offerid){
		  global $bsiCore;
		  $rid=$bsiCore->getRoomtypeId($selected);
		  $cid=$bsiCore->getCapacityId($selected);
		  $day=strtolower(date('D'));		  		  
		  
			
		  /*$extraPrice=0;
		  $ExtraPriceQuery=mysql_query("select price from netbiz_extra_features where extra_features_id IN (".$extraPriceArray.")");
		  if($ExtraPriceQuery === TRUE) {
				
			
			 while($SumExtraPrice=mysql_fetch_array($ExtraPriceQuery))
			 {
				$extraPrice=$extraPrice+ $SumExtraPrice['price'];
			 }
		  }*/
		  
		  $data="";
		  $sql=mysql_query("select * from netbiz_priceplan where roomtype_id=".$rid." and capacity_id=".$cid);
		  if(mysql_num_rows($sql)){			
			$row=mysql_fetch_assoc($sql);
			
			if($offerid!='0')
		  {
			  $offerid=$bsiCore->getRoomtypeId($offerid);
			  $offerPriceQuery=mysql_query("select price_deduc from netbiz_special_offer where id=".$offerid);
			  $getOfferPrice=mysql_fetch_assoc($offerPriceQuery);
			  $offerPrice=($row[$day]*$getOfferPrice["price_deduc"])/100;
			  
		  }
		  else
		  {
			  
			  $offerPrice=$bsiCore->getOfferPrice($selected,'');
		  }
				$TotalPrice=($row[$day]-$offerPrice)+$extraPrice;
				$data.=$TotalPrice;
							
		  }
		  //return $extraPrice;
		  return $data;
	  }
	  
	   public function getOfferPrice($roomtype_ID,$offerid){
		  global $bsiCore;
		  $roomtypeid=$bsiCore->getRoomtypeId($roomtype_ID);
		  $cid=$bsiCore->getCapacityId($roomtype_ID);
		  		 
		  $day=strtolower(date('D'));
		  $data='';
		  $priceDeduc='';
		  if($offerid=='')
		  {
			  $sql=mysql_query("select so.price_deduc FROM netbiz_room_offers AS ro JOIN netbiz_special_offer AS so ON ro.offer_id=so.id where ro.status='y' and ro.roomtype_ID=".$roomtypeid." and ro.capacity_id=".$cid." and so.status='y' order by so.id desc Limit 1");
			  if(mysql_num_rows($sql)){			
				$row=mysql_fetch_assoc($sql);
				$priceDeduc.=$row["price_deduc"];
			  }
		  }
		  else
		  {
			  $ofid=$bsiCore->getRoomtypeId($offerid);
			  $sql=mysql_query("select price_deduc FROM netbiz_special_offer where id=".$ofid);
			  if(mysql_num_rows($sql)){			
				$row=mysql_fetch_assoc($sql);
				$priceDeduc.=$row["price_deduc"];
			  }
		  }
			//$GetPrice=mysql_query("select * from netbiz_priceplan where roomtype_id=".$rid." and capacity_id=".$cid);
			
			//$totalprice=$bsiCore->getTotalPrice($roomtype_ID,'0','0');
			$CostQuery=mysql_query("select ".$day." FROM netbiz_priceplan where roomtype_ID=".$roomtypeid." and capacity_id=".$cid);
			$Cost=mysql_fetch_assoc($CostQuery);
			
			$data.=($Cost[$day]*$priceDeduc)/100;
						
		  		  
		  return $data;
	  }
	  public function getRoomsByRoomType($roomtype_ID){
		  global $bsiCore;
		  $roomtypeid=$bsiCore->getRoomtypeId($roomtype_ID);
		  $cid=$bsiCore->getCapacityId($roomtype_ID);
		  
		  $rooms=array();
		  $sql=mysql_query("select room_no as count FROM netbiz_room where roomtype_id=".$roomtypeid." and capacity_id=".$cid);
		  $row=mysql_fetch_assoc($sql);
		  return $row['count'];
	  }
	  
	  public function getHotel($hotelname){
		  global $bsiCore;
		
		  $data='';
		  $sql=mysql_query("select * FROM netbiz_hotels");
		  if(mysql_num_rows($sql)){			
			while($row=mysql_fetch_assoc($sql))
			{
				if($hotelname==$row['hotel_name'])
				{
					$data.='<option value="'.$row['hotel_id'].'" selected="selected">'.$row['hotel_name'].'</option>';	
				}
				else
				{
					$data.='<option value="'.$row['hotel_id'].'">'.$row['hotel_name'].'</option>';		
				}
			}
		  }		  
		  return $data;
	  }	 
	  
	  public function getHotelIDByName($hotelname){
		  global $bsiCore;
			$data='';
		  $sql=mysql_query("select hotel_id FROM netbiz_hotels where hotel_name='".$hotelname."'");
		  if(mysql_num_rows($sql)){			
			$row=mysql_fetch_assoc($sql);			
			$data=$row['hotel_id'];			
		  }		  
		  return $data;
	  }	 
	  
	  public function getHotelAddress($hotelname){
		  global $bsiCore;
			$data='';
		  $sql=mysql_query("select * FROM netbiz_hotels where hotel_name='".$hotelname."'");
		  if(mysql_num_rows($sql)){			
			$row=mysql_fetch_assoc($sql);	
			$data.=$row['hotel_name'];
			if($row['city']!='')$data.=','.$row['city'];	
			if($row['state']!='')$data.=','.$row['state'];
			if($row['country']!='')$data.=','.$row['country'];
					
		  }		  
		  return $data;
	  }	
	  public function getSavedTotalPrice($user){
		  global $bsiCore;
			$data='';
		  $sql=mysql_query("SELECT sum(total_cost) as total FROM netbiz_booking_details where identity='".$user."' and ispaid='n'");
		  if(mysql_num_rows($sql)){			
			while($row=mysql_fetch_array($sql))
			{	
			
			$data.=$row['total'];
				
			}
					
		  }		  
		  return $data;
	  }	 
	  public function getSavedOrder($user){
		  global $bsiCore;
			$data='';
		  $sql=mysql_query("select * from netbiz_booking_details as bd, netbiz_special_offer as so,netbiz_roomtype as rt,netbiz_capacity as cap where bd.room_type_id=rt.roomtype_ID and bd.capacity_id=cap.id and bd.offer_id=so.id and  bd.identity='".$user."'");
		  if(mysql_num_rows($sql)){			
			while($row=mysql_fetch_array($sql))
			{	
			
			$data.='<table width="738" border="0" cellspacing="1" cellpadding="0">
			<tr>
			<td width="167" height="42" align="left"><h5><strong>Book Room Type</strong><br />
			'.$row['type_name'].' ('.$row['title'].') </h5></td>
			<td width="2" align="center"><img src="images/review_divider.jpg" width="2" height="33" alt="" /></td>
			<td width="143" align="left"><h5><strong>Select Offers</strong><br />
			'.$row['offer_title'].'</h5></td>
			<td width="2" align="center"><img src="images/review_divider.jpg" width="2" height="33" alt="" /></td>
			<td width="143" align="left"><h5><strong>Extra Features</strong><br />';
			
			$data.='</h5></td>
			<td width="2" align="left"><img src="images/review_divider.jpg" width="2" height="33" alt="" /></td>
			<td width="137" align="left"><h5><strong>Checkin Date</strong><br />
			'.$row['from_date'].'</h5></td>
			<td width="2" align="left"><img src="images/review_divider.jpg" width="2" height="33" alt="" /></td>
			<td width="156" align="left"><h5><strong>Checkout Date</strong><br />
			'.$row['to_date'].'</h5></td>
			</tr>
			</table>';
				
			}
					
		  }		  
		  return $data;
	  }	 
	  
	  public function getAboutHotel($hotelname){
		  global $bsiCore;
			$data='';
		  $sql=mysql_query("SELECT * from netbiz_hotels where hotel_name='".$hotelname."'");
		  if(mysql_num_rows($sql)){			
			$row=mysql_fetch_array($sql);
				
				$data.='<div class="owl-demo owl-carousel slider3">';
				$galleryQuery=mysql_query("SELECT * from netbiz_hotel_gallery where hotel_id=".$row['hotel_id']." and status='y'");
				while($gallery=mysql_fetch_array($galleryQuery))
				{
				
				$data.='<div class="item"><img src="gallery/'.$gallery['images_path'].'" alt="" width="740px" height="240px"></div>';                                                                                      
				
				}
				$data.= '</div><div class="gallerydata">'.$row['about'].'</div>';
					
		  }		  
		  return $data;
	  }	
	  public function ChangeTotalByCurrency($currency,$totalcost){
		  global $bsiCore;
			if($currency=='INR')
			{
				$to_Currency='INR';
				$from_Currency='USD';
			}
			else
			{
				$to_Currency='USD';
				$from_Currency='INR';
			}
			$data=$bsiCore->get_currency($from_Currency, $to_Currency, $totalcost);

		  return $data;
	  }
	  public function ChangeSavedByCurrency($currency,$savedcost){
		  global $bsiCore;
			if($currency=='INR')
			{
				$to_Currency='INR';
				$from_Currency='USD';
			}
			else
			{
				$to_Currency='USD';
				$from_Currency='INR';
			}
			$data=$bsiCore->get_currency($from_Currency, $to_Currency, $savedcost);
		  return $data;
	  }		  
}